
import { Component } from "react";

export default class Publish extends Component {
    state = {
        content: ''
    }
    publish = () =>{
        // 通过调用由 props 传递的 add 函数来向父组件传递数据
        this.props.add( this.state.content );
        // 更改本组件的状态
        this.setState({
            content: ''
        });
    }
    handler = evt => {
        this.setState({
            content: evt.target.value
        });
    }
    render(){
        return (
            <div className="input-wrapper">
                <input type="text" value={this.state.content} placeholder="请输入评论内容" onChange={this.handler} />
                <button onClick={this.publish}>发布</button>
            </div>
        );
    }
}